package com.tb.controller;

import com.tb.dubbo.IGoodsAddService;
import com.tb.pojo.Goods2;
import com.tb.pojo.User;
import com.tb.utils.Msg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @api {post} /addGoods/addGoodsing 增加商品接口    王玺玉
 * @apiDescription 增加商品及其详情信息
 * @apiGroup Goods API
 *
 * @apiParam {String}  goodsId 商品id
 * @apiParam {String}  goodsName 商品名称
 * @apiParam {Float}  goodsPrice 商品价格
 * @apiParam {Integer}  goodsNum 商品数量
 * @apiParam {Integer}  goodsKind 商品种类id
 * @apiParam {Float}  goodsWeight 商品重量
 * @apiParam {Float}  goodsDiscount 商品折扣
 *
 * @apiParam {Object}  img 图片对象
 * @apiParam (img) {Integer}  id 图片编号
 * @apiParam (img) {String}  imgUrl 图片链接
 * @apiParam (img) {String}  goodsId 商品id
 *
 * @apiParam {Object}  natures 商品详情对象
 * @apiParam (natures) {Integer}  id 商品详情编号
 * @apiParam (natures) {String}  nature 商品详情名
 * @apiParam (natures) {String}  goodsId 商品编号
 *
 * @apiParam {Object}  naturev 商品详情信息对象
 * @apiParam (naturev) {Integer}  natureId 商品详情编号
 * @apiParam (naturev) {Map}  map 商品详情信息值
 *
 *
 * @apiParamExample {json} 请求参数格式:
 *      {
 * 		"goodsId": "",
 * 		"goodsName": "苹果66s",
 * 		"goodsPrice": 999,
 * 		"goodsNum": 45,
 * 		"goodsKind": 1,
 * 		"goodsWeight": 145,
 * 		"goodsDiscount": null,
 *
 * 	    "img":[{
 * 		    "id":0,
 * 		    "goodsId":"",
 * 			"imgUrl":"ssssssfdgfgfdg"
 * 		},
 * 		{
 * 		    "id":0,
 * 		    "goodsId":"",
 * 			"imgUrl":"dddffffffffff"
 * 		}
 * 		],
 *
 * 		"natures": [{
 * 		    "id":1,
 * 		    "nature":"使用信息",
 * 		    "goodsId":"111",
 * 		    "naturev":[{
 * 		        "natureId":0,
 * 		        "map": {
 * 		           "成色":"9成新"
 * 		       }
 * 		    },
 * 		    {
 * 		        "natureId":0,
 * 		         "map": {
 * 		          "购买渠道":"国行"
 * 		       }
 * 		    }
 *
 * 		        ]
 * 		},
 *
 *         {
 * 		    "id":1,
 * 		    "nature":"型号信息",
 * 		    "goodsId":"111",
 * 		    "naturev":[{
 * 		        "natureId":1,
 * 		       "map": {
 * 		         "品牌":"苹果"
 * 		       }
 * 		    },
 * 		    {
 * 		        "natureId":1,
 * 		       "map": {
 * 		           "机型":"5s"
 * 		       }
 * 		    },
 * 		    {
 * 		        "natureId":1,
 * 		        "map": {
 * 		           "颜色":"金色"
 * 		       }
 * 		    }
 *
 * 		        ]
 * 		},{
 * 		    "id":1,
 * 		    "nature":"参数信息",
 * 		    "goodsId":"111",
 * 		    "naturev":[{
 * 		        "natureId":2,
 * 		       "map": {
 * 		           "内存":"16G"
 * 		       }
 * 		    },
 * 		    {
 * 		        "natureId":2,
 * 		        "map": {
 * 		           "运行内存":"4G"
 * 		       }
 * 		    },
 * 		    {
 * 		        "natureId":2,
 * 		        "map": {
 * 		           "cpu":"双核"
 * 		       }
 * 		    }
 *
 * 		        ]
 * 		}
 * ]
 * }
 *
 * @apiVersion 1.0.0
 *
 * @apiSuccess  {int} code 返回状态码 0:正常 1:错误
 * @apiSuccess  {string} msg 返回错误信息
 * @apiSuccess  {Object} data 返回的成功信息
 *
 * @apiSuccessExample {json} 正确返回值:
 *      {
 *     "code": 0,
 *     "msg": "",
 *     "data":"SUCCESS"
 *     }
 *
 *
 * @apiErrorExample {json} 错误返回值:
 *     {
 *     "code": 1,
 *     "msg": "failed",
 *     "data": null
 * }
 * @apiErrorExample {json} 错误返回值:
 *     {
 *     "code": 999,
 *     "msg": "登录超时",
 *     "data": null
 * }
 * @apiSampleRequest /addGoods/addGoodsing
 */

@RestController
@RequestMapping("/addGoods")
public class AddGoodsController {

    @Autowired
    private IGoodsAddService iGoodsAddService;

    @PostMapping("/addGoodsing")
    public Msg addGoods(@RequestBody Goods2 goods, HttpServletRequest request){

        HttpSession session = request.getSession();
        try {
            User user1 = (User) session.getAttribute("AdminUser");
            user1.getId();
        }catch (Exception e){
            return Msg.error(999,"登录超时");
        }

        boolean b = iGoodsAddService.addGoods(goods);
        if (b==true){
            return Msg.success("SUCCESS");
        }
        return Msg.error(1,"failed");
    }
}
